<div class="main-header" style="padding:0 15px">
  <ul class="nav nav-pills nav-pills-bottomguide">
    <li class="active"> <a href="{MOD_URL}&op=edituser&do=add&orgid=$orgid" onclick="jQuery('#orguser_container').load(this.href);return false;">{lang add_user}</a> </li>
  </ul>
</div>
<div class="main-body" style="padding:15px 15px 15px 22px;">
<div id="return_adduser" style="display:none"></div>
<form id="accountform" name="accountform" class="form-horizontal form-horizontal-left" action="{MOD_URL}&op=edituser" method="post" onsubmit="account_submit();return false">
  <input type="hidden" name="accountadd" value="true" />
  <input type="hidden" name="uid" value="$uid" />
  <input type="hidden" name="handlekey" value="adduser" />
  <input type="hidden" name="formhash" value="{FORMHASH}" />
  <div class="form-group">
    <label class="control-label" for="email">{lang login_email}</label>
    <div class="controls">
      <input type="text" class="form-control input-sm" id="email" name="email" autocomplete="off" value="$user[email]" onblur="checkemail(this.id);">
      <p id="emailmore" style="height:1px;margin:0;">&nbsp;</p>
    </div>
    <span id="chk_email" class="help-inline"> <span id="suc_email"></span><kbd class="p_chk"></kbd>{lang adduser_login_email_text}</span> </div>
  <div class="form-group">
    <label class="control-label" for="username">{lang username}</label>
    <div class="controls">
      <input type="text" class="form-control input-sm" id="username" name="username" placeholder="{lang login_username_placeholder}" autocomplete="off" value="$user[username]" onblur="checknick(this.id);" >
    </div>
    <span id="chk_username" class="help-inline"> <span id="suc_username"></span><kbd class="p_chk"></kbd> {lang login_username_tips} </span> </div>
  <div class="form-group">
    <label class="control-label" for="username">{lang phone_number}</label>
    <div class="controls">
      <input type="text" class="form-control input-sm" class="form-control input-sm" placeholder="{lang weixin_phone_number}" id="phone" name="phone" autocomplete="off" value="$user[phone]">
    </div>
    <span id="chk_phone" class="help-inline">{lang adduser_phone_number_text}</span> </div>
  <div class="form-group">
    <label class="control-label" for="username">{lang weixin}</label>
    <div class="controls">
      <input type="text" class="form-control input-sm" class="form-control input-sm" placeholder="{lang user_weixin}" id="weixinid" name="weixinid" autocomplete="off" value="$user[weixinid]">
    </div>
    <span id="chk_weixinid" class="help-inline">{lang adduser_weixin_text}</span> </div>
  <div class="form-group">
    <label class="control-label" for="password">{lang user_login_password}</label>
    <div class="controls">
      <input type="text" class="form-control input-sm" name="password" autocomplete="off" id="password" placeholder="{lang register_password_tips}">
    </div>
    <span id="chk_password" class="help-inline"> <span id="suc_password"></span> <kbd id="chk_password" class="p_chk"></kbd> </span> </div>
  <div class="form-group">
    <label class="control-label" for="password2">{lang password_confirm}</label>
    <div class="controls">
      <input type="text" class="form-control input-sm" id="password2" name="password2" autocomplete="off" placeholder="{lang register_repassword_tips}">
    </div>
    <span id="chk_password2" class="help-inline"> <span id="suc_password2"></span> <kbd id="chk_password2" class="p_chk"></kbd> </span> </div>
  <div class="form-group">
    <label class="control-label"></label>
    <div class="controls"> <a href="javascript:;" class="btn btn-simple" onclick="randomPass()">{lang random_password}</a> </div>
  </div>
  
  <div class="form-group">
    <label class="control-label" for="">{lang disable_user}</label>
    <div class="controls ml20" style="width:160px;">
      <label class="checkbox-inline"><input type="checkbox" name="status" <!--{if $_G['adminid']!=1}-->disabled="disabled"<!--{/if}--> value="1" <!--{if $user[status]}-->checked<!--{/if}-->>{lang block_up}</label>
    </div>
    <span class="help-inline">{lang adduser_disable_user_text}</span> </div>
  <div class="form-group">
    <label class="control-label" for="">{lang usergroup}</label>
    <div class="controls ml20"> 
      <!-- <label class="checkbox-inline" ><input type="checkbox" name="adminid" <!--{if $_G['adminid']!=1}-->disabled="disabled"<!--{/if}-->value="1"<!--{if $user[adminid]==1}-->checked<!--{/if}-->>{lang set_system_administrator}
      </label>
      --> <select name="groupid" class="form-control" <!--{if $_G[ 'adminid']!=1}-->disabled="disabled"<!--{/if}-->> 
      <!--{loop $_G['cache']['usergroups'] $groupid $group}--> 
      <!--{{if !in_array($groupid ,array('2','3','4','5','6','7','8'))}-->
      <option <!--{if $groupid==9}-->selected="selected"<!--{/if}-->value="$groupid">$group['grouptitle']
      </option><!--{/if}-->
      <!--{/loop}-->
      </select>
    </div>
    <span class="help-inline">{lang adduser_usergroup_text}</span> </div>
  <div class="form-group">
    <label class="control-label" for="depart">{lang department_position}&nbsp;[&nbsp;<a href="javascript:;" class="glyphicon glyphicon-plus" onclick="addorgsel()" title="{lang add_a_item}"></a>&nbsp;]</label>
    <div id="selorg_container" class="controls selorg-container"> 
      <!--{if $org}-->
      <ul class="nav nav-pills">
        <li class="dropdown org">
          <input id="sel_orgid_{$org[orgid]}" type="hidden" name="orgids[]" value="$org[orgid]" onchange="selDepart(this)" />
          <button type="button" id="orgid_{$org[orgid]}_Menu" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> $org[depart] <span class="caret"></span> </button>
          <div id="orgid_$orgid_dropdown_menu" class="dropdown-menu org-sel-box" role="menu" aria-labelledby="orgid_{$org[orgid]}_Menu">
            <iframe name="orgid_{$org[orgid]}_iframe" class="org-sel-box-iframe" src="index.php?mod=system&op=orgtree&ctrlid=orgid_{$org[orgid]}&nouser=1&moderator=1" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" allowtransparency="true"></iframe>
          </div>
        </li>
        <li class="dropdown job">
          <input type="hidden" name="jobids[]" value="0" />
          <a href="javascript:;" data-toggle="dropdown" role="button" _jobid="0" class="dropdown-toggle btn btn-simple jobid"><span>{lang none}</span><b class="caret"></b></a>
          <ul aria-labelledby="drop-depart" role="menu" class="dropdown-menu">
            <li role="presentation"> <a href="javascript:;" tabindex="-1" role="menuitem" _jobid="0" onclick="selJob(this)">{lang none}</a> </li>
            <!--{loop $org[jobs] $value1}-->
            <li role="presentation"> <a href="javascript:;" tabindex="-1" role="menuitem" _jobid="$value1['jobid']" onclick="selJob(this)">$value1[name]</a> </li>
            <!--{/loop}-->
          </ul>
        </li>
        <li> <a style="margin:0 10px 10px 0;" href="javascript:;" onclick="delDepart(this)" ttitle="{lang delete}"><i class="glyphicon glyphicon-remove"></i></a> </li>
      </ul>
      <!--{/if}-->
      <ul id="nav" class="nav nav-pills">
        <li class="dropdown org">
          <input id="sel_orgid_tpml" type="hidden" name="orgids[]" value="0" onchange="selDepart(this)" />
          <button type="button" id="orgid_tpml_Menu" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> {lang please_select_a_organization_or_department} <span class="caret"></span> </button>
          <div id="orgid_tpml_dropdown_menu" class="dropdown-menu org-sel-box" role="menu" aria-labelledby="orgid_tpml_Menu">
            <iframe name="orgid_tpml_iframe" class="org-sel-box-iframe" src="index.php?mod=system&op=orgtree&ctrlid=orgid_tpml&nouser=1&moderator=1" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" allowtransparency="true"></iframe>
          </div>
        </li>
        <li class="dropdown job">
          <input type="hidden" name="jobids[]" value="0" />
          <a href="javascript:;" data-toggle="dropdown" role="button" _job="0" class="dropdown-toggle btn btn-simple jobid"><span>{lang none}</span><b class="caret"></b></a>
          <ul aria-labelledby="drop-job" role="menu" class="dropdown-menu">
          </ul>
        </li>
        <li> <a href="javascript:;" onclick="delDepart(this)" ttitle="{lang delete}"><i class="glyphicon glyphicon-remove"></i></a> </li>
      </ul>
    </div>
  </div>
  <div class="form-group">
    <label class="control-label" for="">{lang supervisor_position}</label>
    <div id="upjob" class="controls selorg-container">
      <ul class="nav nav-pills">
        <li class="dropdown org">
          <input id="sel_uporgid" type="hidden" name="uporgid" value="0" onchange="selDepart(this)" />
          <button type="button" id="uporgid_Menu" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> {lang please_select_a_organization_or_department} <span class="caret"></span> </button>
          <div id="uporgid_dropdown_menu" class="dropdown-menu org-sel-box" role="menu" aria-labelledby="uporgid_Menu">
            <iframe name="uporgid_iframe" class="org-sel-box-iframe" src="index.php?mod=system&op=orgtree&ctrlid=uporgid&nouser=1" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" allowtransparency="true"></iframe>
          </div>
        </li>
        <li class="dropdown job">
          <input type="hidden" name="upjobid" value="0">
          <a href="javascript:;" data-toggle="dropdown" role="button" _jobid="0" class="dropdown-toggle btn btn-simple jobid"><span>{lang none}</span><b class="caret"></b></a>
          <ul aria-labelledby="drop-job" role="menu" class="dropdown-menu">
            <li role="presentation"> <a href="javascript:;" tabindex="-1" role="menuitem" _jobid="0" onclick="selJob(this)">{lang none}</a> </li>
          </ul>
        </li>
      </ul>
    </div>
  </div>
  <div class="form-group">
    <label class="control-label"></label>
    <div class="controls">
      <input type="button" class="btn btn-success" value="{lang confirm_add}" onclick="account_submit()">
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <label class="checkbox-inline">
        <input type="checkbox" name="sendmail" value="1" checked="checked" >
        {lang send_password_user_mailbox}</label>
    </div>
  </div>
</form>
</div>
<script type="text/javascript" reload="1">
	var orgsel_html = jQuery('#nav').html();
	var lastusername = '',
		lastpassword = '',
		lastemail = '',
		lastinvitecode = '',
		stmp = new Array(),
		modifypwd = false;
	var pwlength = 0;
	var strongpw = new Array();
	var ignoreEmail = false;
	checkPwdComplexity(document.getElementById('password'),document.getElementById('password2'), false);

	function account_submit() {

		//判断用户名
		if(jQuery('#email').val() == '') {
			jQuery('#email').focus();
			showmessage('{lang login_email_required}', 'danger', 1000, 1);
			return false;
		}
		if(jQuery('#username').val() == '') {
			jQuery('#username').focus();
			showmessage('{lang name_will}', 'danger', 1000, 1);
			return false;
		}

		if(jQuery('#password').val() == '') {
			jQuery('#password').focus();
			showmessage('{lang none_write_login_password}', 'danger', 1000, 1);
			return false;
		}
		if(jQuery('#password2').val() == '') {
			showmessage('{lang none_write_affirm_password}', 'danger', 1000, 1);
			jQuery('#password2').focus();
			return false;
		}
		if(jQuery('#password').val() != jQuery('#password2').val()) {
			showmessage('{lang profile_passwd_notmatch}', 'danger', 1000, 1);
			jQuery('#password').focus();
			return false;
		}
	
		var flag = 0;
		jQuery('#accountform kbd').each(function(){
			var self=jQuery(this);
			if(self.hasClass('p_chk') && self.html() != '') {
				flag=1;
				return false;
			}
		});
		if(flag) return false;
		//判定微信号和手机
		var phone = jQuery('#phone').val();
		if(phone != '' && phone.match(/^\d+$/) == null) {
			jQuery('#phone').focus();
			showmessage('{lang phone_number_illegal}', 'danger', 1000, 1);
			return false;
		}
		var weixinid = jQuery('#weixinid').val();
		if(weixinid != '' && weixinid.match(/^[a-zA-Z\d_]{5,}$/) == null) {
			jQuery('#weixinid').focus();
			showmessage('{lang weixin_illegal}', 'danger', 1000, 1);
			return false;
		}

		ajaxpost('accountform', 'ajaxwaitid', 'return_adduser');
		return false;
	}

	function succeedhandle_adduser(url, message, values) {
		var uid = values['uid'];
		var orgids = values['orgids'];
		showDetail(uid, 'user');
		var inst = jQuery("#classtree").jstree(true);
		inst.refresh(true);
		showmessage(message, 'success', 3000, 1);
	};

	function errorhandle_adduser(msg, values) {
		showmessage(msg, 'danger', 3000, 1);
	}

	jQuery(document).ready(function(e) {
		jQuery('.dropdown-menu li.disabled a').on('click', function() {
			return false;
		});
	});

	function randomPass() {
		var pass = (Math.round(Math.random() * 100000000));
		jQuery('#password').val(pass).trigger('blur');
		jQuery('#password2').val(pass).trigger('blur');
	}
</script>